<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var room = {
                name: "汤臣一品",
                price: 100,
                phone: "18800000000"
            }
            // proxy代理 是对 对象的访问  和 赋值操作的拦截

        var proom = new Proxy(room, {
            get(target, key) {
                // target 代理的对象 key 键值
                if (key == "price") {
                    return target[key] + 20
                } else if (key == "phone") {
                    return target[key].substr(0, 3) + "****" + target[key].substr(7)
                } else {
                    return target[key]
                }
            },
            set(target, key, val) {
                console.log(target, key, val)
                    // target--代理对象
                    // key 键
                    // val 赋值的新的值
                if (key == "price") {
                    if (val > 200) {
                        target[key] = 200;
                    } else {
                        target[key] = val;
                    }
                }
            }
        })
        console.log(proom.price)
        console.log(proom.phone)
        proom.price = 260;
        console.log(proom)
    </script>
</body>

</html>